home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / textwndw.swg / 0016_Pausing Text Output.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-03-26  |  3.5 KB  |  102 lines

  1. {
  2. > I can't find a procedure to call and display a text
  3. > to the screen inside a window [window(1,2,80,24)] and be able to put pauses
  4. > scrolling into it if'n it takes up more than 23 lines of text.
  5.  
  6. I took a swing at this when I saw your message.  I wrote a little unit called
  7. BuffrTxt that should be pretty self-explainatory, since I was so generous
  8. with my comments.  Is this pretty much what you were looking for?
  9.  
  10. { **********************************************************************
  11.   *                           BufferText                               *
  12.   *                               by                                   *
  13.   *                         Todd A. Jacobs                            *
  14.   *                                                                   *
  15.   *        Buffers a text file to prevent a view port overflow.        *
  16.   **********************************************************************
  17.  
  18. This code is hereby released into the public domain.  This program was an
  19. excercise I did when someone asked about how to read a text file into a
  20. text window without having it all scroll off the screen.
  21.  
  22. This unit buffers the text into an array which is based on how many lines
  23. exist between the upper and lower boundaries of the window.  One of the
  24. problems with doing it this way is that if the text read in is the same
  25. width as the view port, it will wrap--thereby throwing off the buffer.  To
  26. "solve" this, I elected to truncate the lines to prevent wrapping. }
  27.  
  28. Unit BuffrTxt;
  29.  
  30. Interface
  31.  
  32. Var
  33.   Lines : Byte;
  34.  
  35. {Example parameters for DefineWindow:
  36.  
  37.     DefineWindow (10, 3, 70, 23, 1, 15);
  38.  
  39. The first four XY parameters are self-explanitory.  BG & FG set the
  40. background and foreground colors for the text viewport. }
  41. Procedure DefineWindow (ULeftX, ULeftY, LRightX, LRightY, BG, FG : BYTE);
  42. Procedure ReadFile (FileName : String);
  43.  
  44. {By keeping all the details hidden inside the implementation, you won't
  45. have to recompile every piece of source you have used this with if you
  46. change one of the constants, because the interface will remain the same. }
  47. Implementation
  48.  
  49. Uses Crt;
  50.  
  51. Const
  52.   PauseStr = '-=[ Press any key to continue ]=-';
  53.   MaxScrWidth = 80;
  54.   MaxArraySize = 25;
  55.  
  56. Procedure DefineWindow;
  57. Begin {DefineWindow}
  58.   Lines := LRightY - ULeftY; {Sets boundaries for use in ReadFile}
  59.   Window (ULeftX, ULeftY, LRightX, LRightY);
  60.   TextBackground (BG);
  61.   TextColor (FG);
  62.   ClrScr;
  63. End; {DefineWindow}
  64.  
  65. Procedure ReadFile;
  66.  
  67. {Set the size of the array from the window boundaries as defined in
  68. the constants}
  69. Type
  70.   StringArray = Array [1..MaxArraySize] of String[MaxScrWidth];
  71. Var
  72.   F: Text;
  73.   TmpBuf: String[MaxScrWidth]; {Will truncate longer lines to prevent wrap}
  74.   StrBuf: StringArray;  {This buffer holds 25 lines of 80 cols each}
  75.   Counter1, Counter2: Byte;
  76.  
  77. Begin {ReadFile}
  78.   Assign(F, FileName);
  79.   Reset(F);
  80.   While not Eof(F) do
  81.   Begin
  82.     {Initialize the counters each time through the loop}
  83.     Counter1 := 0;
  84.     Counter2 := 0;
  85.     Repeat  {This is where the buffer is restricted to Y2 - Y1 Lines}
  86.      Inc (Counter1);
  87.      Readln(F, TmpBuf);
  88.      StrBuf[Counter1] := TmpBuf;
  89.     Until Eof(F) or (Counter1 = Lines);  {Also prevents reading past EOF}
  90.  
  91.     {Write buffered lines to the screen}
  92.     For Counter2 := 1 to Counter1 do
  93.      Writeln (StrBuf[Counter2]);
  94.     Write (PauseStr);
  95.     Readln;
  96.   End; {Goes back for more buffering "while not EOF"}
  97.   Close(F);
  98. End; {ReadFile}
  99.  
  100. End.  {Unit}
  101.  
  102.